<template>
  <div class="approval">
    <el-card class="box-card" style="margin-bottom: 10px;">
      <div class="head-title">
        <div class="title">{{$t('approvalDetail.RegisterInfo')}}</div>
      </div>
      <div class="detail-info">
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.RegisterPhoneNum')}}:</span>
          <span>{{orderOtherInfoObj.userName}}</span>
          <span class="cell-phone-result">{{endPhone}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.customerCrtTime')}}:</span>
          <span>{{orderOtherInfoObj.registerTime}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.RegisterChannel')}}:</span>
          <span v-if="orderOtherInfoObj.userSource === ''" key="1"></span>
          <span v-else-if="orderOtherInfoObj.userSource === 'organic'" key="2">{{$t('approvalDetail.NaturalFlow')}}</span>
          <span v-else-if="orderOtherInfoObj.userSource === 'channel4tel' || orderOtherInfoObj.userSource === 'channel4sms'" key="3">{{$t('approvalDetail.ElectricSales')}}</span>
          <span v-else key="4">{{$t('approvalDetail.UnnaturalFlow')}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.regGps')}}:</span>
          <span>{{orderOtherInfoObj.registerAddress}}</span>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-bottom: 10px;">
      <div class="head-title">
        <div class="title">{{$t('approvalDetail.orderInfo')}}</div>
        <div class="info" v-show="this.continue === this.$t('approvalDetail.ContinuedLoan')">
          <span>{{this.continue}}</span>
          <button
            type="button"
            @click="seeLoanHistory"
          >{{$t('approvalDetail.seehis')}}</button>
        </div>
      </div>
      <div class="detail-info">
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.loanApp')}}:</span>
          <span>{{orderOtherInfoObj.appAllName}}</span>
        </div>
      </div>
      <div class="detail-info">
        <div class="detail-info-item">
          <span>{{$t('collDetail.orderIds')}}:</span>
          <span>{{orderOtherInfoObj.orderId}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approval.proName')}}:</span>
          <span>{{orderOtherInfoObj.pName}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.AppliyQuota')}}:</span>
          <span>{{orderOtherInfoObj.applyMoney}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approval.time')}}:</span>
          <span>{{orderOtherInfoObj.applyTime}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.proTerm')}}:</span>
          <span>{{orderOtherInfoObj.pTerm}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('expireRemind.serviceFee')}}:</span>
          <span>{{orderOtherInfoObj.serviceCharge}}</span>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-bottom: 10px;">
      <div class="head-title">
        <div class="title">{{$t('approvalDetail.BorrowDemand')}}</div>
      </div>
      <div class="detail-info">
        <div class="detail-info-item">
          <span style="width: 140px;">{{$t('approvalDetail.needSum')}}:</span>
          <span>{{orderOtherInfoObj.needMoney}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.usageLoan')}}:</span>
          <span>{{orderOtherInfoObj.moneyToDo}}</span>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-bottom: 10px;">
      <div class="head-title">
        <div class="title">{{$t('approvalDetail.equip')}}</div>
      </div>
      <div class="detail-info version">
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.phoneName')}}:</span>
          <span>{{orderOtherInfoObj.phoneBrand}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.andVersion')}}:</span>
          <span>{{orderOtherInfoObj.androidVersion}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.insDate')}}:</span>
          <span>{{orderOtherInfoObj.installDate}}</span>
        </div>
        <div class="detail-info-item">
          <span>{{$t('approvalDetail.appVersion')}}:</span>
          <span>{{orderOtherInfoObj.appVersion}}</span>
        </div>
      </div>
    </el-card>
    <el-dialog :title="$t('approvalDetail.loanhis')" :visible.sync="loanHistory">
      <div class="loan-info">
        <div class="loan-item">
          <span>{{$t('approvalDetail.realName')}}:</span>
          <span>{{orderOtherInfoObj.realName}}</span>
        </div>
        <div class="loan-item">
          <span>{{$t('approvalDetail.phoneNo')}}:</span>
          <span>{{orderOtherInfoObj.userName}}</span>
        </div>
        <div class="loan-item">
          <span>{{$t('approvalDetail.bankCards')}}:</span>
          <span>{{orderOtherInfoObj.bankCard}}</span>
        </div>
      </div>
      <el-table :data="historyTable" border stripe style="width: 100%">
        <el-table-column
          header-align="center"
          align="center"
          :label="$t('approvalDetail.num')"
          type="index"
          width="65"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          :label="$t('approvalDetail.orderId')"
          width="200"
        >
          <template slot-scope="scope">
            <span>{{scope.row.orderId}}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="proName"
          :label="$t('approvalDetail.proName')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="crtTime"
          :label="$t('approvalDetail.crtTime')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="lendDate"
          :label="$t('approvalDetail.loanTime')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="applyAmt"
          :label="$t('approvalDetail.applyAmts')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="neteceipts"
          :label="$t('approvalDetail.neteceipts')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="lastPayDate"
          :label="$t('approvalDetail.lastPayDate')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="realRepayDate"
          :label="$t('approvalDetail.realRepayDate')"
          width="200"
        ></el-table-column>
        <el-table-column
          header-align="center"
          align="center"
          prop="status"
          :label="$t('approvalDetail.orderStatus')"
          width="200"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.status=== 3">{{$t('approvalDetail.status1')}}</span>
            <span v-if="scope.row.status=== 4">{{$t('approvalDetail.status2')}}</span>
            <span v-if="scope.row.status=== 5">{{$t('approvalDetail.status3')}}</span>
            <span v-if="scope.row.status=== 6">{{$t('approvalDetail.status4')}}</span>
            <span v-if="scope.row.status=== 7">{{$t('approvalDetail.status5')}}</span>
            <span v-if="scope.row.status=== 8">{{$t('approvalDetail.status6')}}</span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="loanHistory = false">{{$t('btn.close')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  getLoanInfo,
  appAllChannel,
  yinHangOrderPage,
  teltIdCheckResult,
  hisPage
} from "api/trust/firstApprDetails/index";
export default {
  data() {
    return {
      listObj: {},
      orderOtherInfoObj: {},
      lanStatus: null,
      cellPhoneId: "",
      continue: "",
      loanHistory: false,
      historyTable: []
    };
  },
  computed: {
    ...mapGetters(["elements", "language", "endApprDetails", "endPhone"])
  },
  created() {
    this.getParamsDetail();
    if (this.language === "zh") {
      this.lanStatus = 1;
    } else if (this.language === "en") {
      this.lanStatus = 2;
    } else {
      this.lanStatus = 3;
    }
    // 手机号实名认证
    // let telResultObj = {};
    // telResultObj.orderId = this.listObj.orderId;
    // telResultObj.lanStatus = this.lanStatus;
    // teltIdCheckResult(telResultObj).then(res => {
    //   if (res.status === 200) {
    //     this.cellPhoneId = res.data;
    //   }
    // });
    // 注册信息 订单信息 借款需求 设备信息
    let otherInfoObj = {};
    otherInfoObj.orderId = this.listObj.orderId;
    otherInfoObj.userId = this.listObj.userId;
    otherInfoObj.userUUID = this.listObj.userUUID;
    otherInfoObj.msgType = this.lanStatus;
    getLoanInfo(otherInfoObj).then(res => {
      if (res.status === 200) {
        let re = /(?=(?!\b)(\d{3})+$)/g;
        let str = String(res.data.applyMoney)
        res.data.applyMoney = str.replace(re, ',');
        let str2 = String(res.data.serviceCharge)
        res.data.serviceCharge = str2.replace(re, ',');
        this.orderOtherInfoObj = res.data;
        this.$emit('applyAmtEvent', res.data.applyMoney)
        if (res.data.flag === 0) {
          this.continue = this.$t('approvalDetail.no')
        } else if (res.data.flag === 1) {
          this.continue = this.$t('approvalDetail.ContinuedLoan')
        }
      }
    });
  },
  methods: {
    getParamsDetail() {
      this.listObj = this.endApprDetails;
    },
    // 查看借款历史
    seeLoanHistory() {
      //历史记录
      let hisObj = {};
      hisObj.orderId = this.listObj.orderId;
      hisPage(hisObj).then(res => {
        if (res.status === 200) {
          res.data.forEach(item => {
            let re = /(?=(?!\b)(\d{3})+$)/g;
            let str = String(item.applyAmt)
            item.applyAmt = str.replace(re, ',');
            let str2 = String(item.neteceipts)
            item.neteceipts = str2.replace(re, ',');
          })
          this.historyTable = res.data;
          this.loanHistory = true;
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
input::-webkit-input-placeholder {
  font-size: 12px;
}
.approval-detail {
  width: 100%;
  height: 100%;
  padding-top: 10px;
  padding-left: 10px;
  padding-right: 10px;
  box-sizing: border-box;
  position: relative;
}
.title {
  line-height: 22px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.detail-info {
  margin-left: 12px;
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  .detail-info-item {
    width: 33%;
    line-height: 25px;
    display: flex;
    flex-wrap: wrap;
    padding-right: 10px;
    box-sizing: border-box;
    span:nth-child(1) {
      display: inline-block;
      width: 120px;
      text-align: left;
      margin-right: 5px;
      color: #616264;
    }
    span:nth-child(2) {
      flex: 1;
      color: #8a8a8c;
      display: inline-block;
      line-height: 25px;
    }
  }
}
.version {
  .detail-info-item {
    width: 25%;
  }
}
.head-title {
  display: flex;
  line-height: 22px;
  .info {
    line-height: 28px;
    border: 1px solid #333;
    margin-left: 20px;
    font-size: 12px;
    border-radius: 5px;
    padding: 0 8px;
  }
}
.results {
  margin-left: 5px;
  color: #20a0ff;
  text-decoration: underline;
}
.info > button {
  padding: 0 15px;
  height: 28px;
  line-height: 28px;
  outline: none;
  border-width: 0;
  border-radius: 4px;
  font-size: 12px;
  background: #ebf5ff;
  color: #20a0ff;
  border: 1px solid #abd5ff;
  margin-left: 10px;
}
.loan-info {
  width: 100%;
  display: flex;
  padding: 10px 0;
  box-sizing: border-box;
  .loan-item {
    width: 30%;
    text-align: left;
    span:nth-child(1) {
      margin-right: 5px;
    }
  }
}
.cell-phone-result {
    background: #20a0ff;
    border-radius: 8px;
    padding: 2px 4px;
    color: #fff;
    margin-left: 5px;
}
</style>